package com.cy.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectionDemo {

	@SuppressWarnings("rawtypes")
	public static void main(String[] args) {
		String str = "com.cy.reflection.R";
		try {
			Class c = Class.forName(str);
			Object o = c.newInstance();
			Method[] methods = c.getMethods();
			for(Method m : methods) {
//				System.out.println(m.getName());
				if(m.getName().equals("m")) {
					m.invoke(o);
				}
				if(m.getName().equals("mm")) {
					m.invoke(o,"fdsfdsfadsf");
					//获取返回值类型
					Class returntype = m.getReturnType();
					System.out.println(returntype.getName());
					//获取参数类型
					Class [] paramtype = m.getParameterTypes();
					for(Class cl : paramtype) {
						System.out.println(cl.getName());
					}
				}
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}

class R {
	static {
		System.out.println("RRRRRRRRRRRRRRRRRRRRRRRRR");
	}
	
	public void m() {
		System.out.println("MMMMMMMMMMMM");
	}
	
	public void mm(String s) {
		System.out.println(s);
	}
}